﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Presentation.cs" company="DissingNelleman">
//   
// All rights reserved. </copyright>
// <summary>
//   The presentation.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace ServiceLibrary.Services.Dto
{
    using System;
    using System.Runtime.Serialization;

    /// <summary>
    /// The presentation.
    /// </summary>
    [DataContract]
    public class Presentation
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        [DataMember]
        public Guid ID { get; set; }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        [DataMember]
        public string Name { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The convert.
        /// </summary>
        /// <param name="presentation">
        /// The presentation.
        /// </param>
        /// <returns>
        /// The <see cref="Presentation"/>.
        /// </returns>
        public static Presentation Convert(Models.Domain.Presentation presentation)
        {
            if (presentation != null)
            {
                var dto = new Presentation { ID = presentation.ID, Name = presentation.Name };
                return dto;
            }
            
            return null;
        }

        #endregion
    }
}

namespace ServiceLibrary.Services.Queries
{
    using System.Runtime.Serialization;

    using NHibernate;

    using ServiceLibrary.Actioners.Activities;
    using ServiceLibrary.Services.Results;

    /// <summary>
    /// The presentation query.
    /// </summary>
    [DataContract]
    public class PresentationQuery : IQuery
    {
        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <returns>
        /// The <see cref="IResult"/>.
        /// </returns>
        public override IResult Execute(ISession hsession)
        {
            var actioner = new PresentationActioner(hsession, null);
            return actioner.ExecuteSearchQuery(this);
        }

        #endregion
    }
}

namespace ServiceLibrary.Services.Results
{
    using System.Collections.Generic;
    using System.Runtime.Serialization;

    using ServiceLibrary.Services.Dto;

    /// <summary>
    /// The presentation result.
    /// </summary>
    [DataContract]
    public class PresentationResult : IResult
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="PresentationResult"/> class.
        /// </summary>
        public PresentationResult()
        {
            this.List = new List<Presentation>();
        }

        #endregion

        #region Public Properties

        /// <summary>
        /// Gets or sets the list.
        /// </summary>
        [DataMember]
        public List<Presentation> List { get; set; }

        /// <summary>
        /// Gets or sets the total row count.
        /// </summary>
        [DataMember]
        public int TotalRowCount { get; set; }

        #endregion
    }
}

namespace ServiceLibrary.Services.Commands
{
    using System;
    using System.Runtime.Serialization;

    using NHibernate;

    using ServiceLibrary.Actioners.Activities;
    using ServiceLibrary.Services.Dto;

    using User = ServiceLibrary.Models.Domain.User;

    /// <summary>
    /// The create presentation command.
    /// </summary>
    [DataContract]
    public class CreatePresentationCommand : ICommand
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the dto.
        /// </summary>
        [DataMember]
        public Presentation Dto { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <param name="activeUser">
        /// The active user.
        /// </param>
        public override void Execute(ISession hsession, User activeUser)
        {
            var actioner = new PresentationActioner(hsession, activeUser);
            actioner.CreatePresentation(this);
        }

        #endregion
    }

    /// <summary>
    /// The update presentation command.
    /// </summary>
    [DataContract]
    public class UpdatePresentationCommand : ICommand
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the dto.
        /// </summary>
        [DataMember]
        public Presentation Dto { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <param name="activeUser">
        /// The active user.
        /// </param>
        public override void Execute(ISession hsession, User activeUser)
        {
            var actioner = new PresentationActioner(hsession, activeUser);
            actioner.UpdatePresentation(this);
        }

        #endregion
    }

    /// <summary>
    /// The delete presentation command.
    /// </summary>
    [DataContract]
    public class DeletePresentationCommand : ICommand
    {
        #region Public Properties

        /// <summary>
        /// Gets or sets the dto.
        /// </summary>
        [DataMember]
        public Guid? Dto { get; set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="hsession">
        /// The hsession.
        /// </param>
        /// <param name="activeUser">
        /// The active user.
        /// </param>
        public override void Execute(ISession hsession, User activeUser)
        {
            var actioner = new PresentationActioner(hsession, activeUser);
            actioner.DeletePresentation(this);
        }

        #endregion
    }
}